//
//  UtilsDefine.h
//  CpicPeriodicaliPad
//
//  Created by magicmac on 12-9-3.
//  Copyright (c) 2012年 magicpoint. All rights reserved.
//

#ifndef CpicPeriodicaliPad_UtilsDefine_h
#define CpicPeriodicaliPad_UtilsDefine_h


#define PARSE_ERROR @"parse_error"
#define MY_TASK_RELOAD @"my_task_reload"



#define CMD_JYM @"JYM"

// 屏蔽输出
#ifdef DEBUG
#   define ILog(fmt, ...) {NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);}
#   define DLog(...) NSLog(__VA_ARGS__)
#   define ELog(err) if(err) ILog(@"%@", err)}
#else
#   define ILog(...)
#   define DLog(...) /* */
#   define ELog(err)
#endif

// 安全release
#define RELEASE_SAFELY(__POINTER) if(__POINTER){ [__POINTER release]; __POINTER = nil; }


// 自动适应 arc 和 非arc
// strong/weak  对应  retain/assign
#ifndef Y_STRONG
#if __has_feature(objc_arc)
    #define Y_STRONG strong
#else
    #define Y_STRONG retain
#endif
#endif

#ifndef Y_WEAK
#if __has_feature(objc_arc_weak)
    #define Y_WEAK weak
#elif __has_feature(objc_arc)
    #define Y_WEAK unsafe_unretained
#else
    #define Y_WEAK assign
#endif
#endif

// autorelease/release/retain 。copy 不用定义，arc和非arc一样。
#if __has_feature(objc_arc)
    #define Y_AUTORELEASE(exp) exp
    #define Y_RELEASE(exp) exp
    #define Y_RETAIN(exp) exp
#else
    #define Y_AUTORELEASE(exp) [exp autorelease]
    #define Y_RELEASE(exp) RELEASE_SAFELY(exp)
    #define Y_RETAIN(exp) [exp retain]
#endif


// resource path
#define kResourcePath(__Name,__Type) {[[NSBundle mainBundle] pathForResource:__Name ofType:__Type]}


// 取系统版本，e.g.  4.0 5.0
#define kSystemVersion [[[UIDevice currentDevice] systemVersion] floatValue]

// 是否iphone5
//#define kIsIphone5 [UIScreen mainScreen].applicationFrame.size.height > 500
#define kIsIphone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

// 屏幕大小
#define kScreenFrame [UIScreen mainScreen].applicationFrame

#define MyAppDelegate (AppDelegate *)[[UIApplication sharedApplication] delegate]

// 判断string是否为空 nil 或者 @""；
#define IsNilString(__String) (__String==nil || [__String isEqualToString:@""])


// 横屏的frame
#define LANDSCAPE_FRAME CGRectMake(0, 20, 1024, 768-20)
#define LANDSCAPE_WIDTH 1024.0

// 竖屏的frame
#define PORTRAIT_FRAME CGRectMake(0, 20, 768, 1024-20)
//#define PORTRAIT_WIDTH 768.0
#define PORTRAIT_WIDTH 320.0

//RGB color macro
#define UIColorFrom0xRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
//RGB color macro with alpha
#define UIColorFrom0xRGBWithAlpha(rgbValue,a) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:a]

// 从frame 中 获取 bound，即把 x、y 都改为0
CG_INLINE CGRect
CGRectBoundsFromFrame(CGRect frame)
{
    CGRect rect;
    rect.origin.x = 0; rect.origin.y = 0;
    rect.size.width = frame.size.width; rect.size.height = frame.size.height;
    return rect;
}

#endif
